home *** CD-ROM | disk | FTP | other *** search
/ Exame Informatica 140 / Exame Informatica 140.iso / Internet / Adblock / adblock-0.5.3.043-fx+fl+mz+ns.xpi / components / nsAdblock.js < prev   
Text File  |  2006-06-30  |  4KB  |  93 lines

  1. const _ADBLOCK_CONTRACTID = "@mozilla.org/adblock;1";
  2. const _ADBLOCK_CID = Components.ID('{34274bf4-1d97-a289-e984-17e546307e4f}');
  3. const _CATMAN_CONTRACTID = "@mozilla.org/categorymanager;1";
  4.  
  5.  
  6. /*
  7.  * Module object
  8.  */
  9.  
  10. var module = {
  11.     console: Components.classes["@mozilla.org/consoleservice;1"].getService(Components.interfaces.nsIConsoleService),
  12.     log: function(msg) { this.console.logStringMessage(msg); },
  13.  
  14.     registerSelf: function(compMgr, fileSpec, location, type) {
  15.         compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
  16.         compMgr.registerFactoryLocation(_ADBLOCK_CID, "Adblock content policy", _ADBLOCK_CONTRACTID, fileSpec, location, type);
  17.         var catman = Components.classes[_CATMAN_CONTRACTID].getService(Components.interfaces.nsICategoryManager);
  18.         catman.addCategoryEntry("content-policy", _ADBLOCK_CONTRACTID, _ADBLOCK_CONTRACTID, true, true);
  19.         this.console = Components.classes["@mozilla.org/consoleservice;1"].getService(Components.interfaces.nsIConsoleService);
  20.         if (typeof policy == 'undefined') this.policy.loadFromProfile();
  21.         try {
  22.             var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
  23.             observerService.addObserver(this, "Adblock-LoadFromProfile", true);
  24.         } catch (e) { this.log("Adblock content policy registration: exception when registering saveprefs observer: " + e + "\n"); }
  25.     },
  26.     unregisterSelf: function(compMgr, fileSpec, location) {
  27.         compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
  28.         compMgr.unregisterFactoryLocation(_ADBLOCK_CID, fileSpec);
  29.         var catman = Components.classes[_CATMAN_CONTRACTID].getService(Components.interfaces.nsICategoryManager);
  30.         catman.deleteCategoryEntry("content-policy", _ADBLOCK_CONTRACTID, true);
  31.     },
  32.     getClassObject: function(compMgr, cid, iid) {
  33.         if (!cid.equals(_ADBLOCK_CID))
  34.             throw Components.results.NS_ERROR_NO_INTERFACE;
  35.         if (!iid.equals(Components.interfaces.nsIFactory))
  36.             throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
  37.         
  38.         if (typeof policy == 'undefined') this.policy.loadFromProfile();
  39.         return (typeof policy !='undefined') ? factory : this;
  40.     },
  41.     canUnload: function(compMgr) {
  42.         return true;
  43.     },
  44.     
  45.     // nsIContentPolicy (placeholder)
  46.     policy: {
  47.         count: 0,
  48.         loadFromProfile: #10=function(){  
  49.             if (typeof policy == 'undefined') {
  50.                 try{ 
  51.                     var SubScriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"].createInstance(Components.interfaces.mozIJSSubScriptLoader);
  52.                     SubScriptLoader.loadSubScript("chrome://adblock/content/component.js"); 
  53.                     this.shouldLoad = policy.shouldLoad, this.shouldProcess=policy.shouldProcess;
  54.                 }catch(e){ 
  55.                     //if (++this.count<10||(100%this.count==0 && this.count<2000)) 
  56.                     //    module.log('typeof policy: '+(typeof(policy))+" -> "+this.count+"\n"+e+'\n\ncaller: '+arguments.callee.caller);
  57.                 }
  58.             }
  59.             return 1;
  60.         },
  61.         shouldLoad: #10#,  shouldProcess: #10#,
  62.         QueryInterface: function(iid) { 
  63.             return (typeof policy !='undefined') ? policy : this; 
  64.         }
  65.     },
  66.     // nsIFactory
  67.     createInstance: function(outer, iid) {
  68.         if (outer != null) throw Components.results.NS_ERROR_NO_AGGREGATION;
  69.         if (typeof policy == 'undefined') this.policy.loadFromProfile();
  70.         return (typeof policy !='undefined') ? policy : this.policy;
  71.     },
  72.     // nsIObserver
  73.     observe: function(subject, topic, prefName) { 
  74.         if (topic == "Adblock-LoadFromProfile")
  75.             if (typeof policy == 'undefined') this.policy.loadFromProfile();
  76.     },
  77.     QueryInterface: function(iid) {
  78.         if (!iid.equals(Components.interfaces.nsISupports) &&
  79.             !iid.equals(Components.interfaces.nsISupportsWeakReference) &&
  80.             !iid.equals(Components.interfaces.nsIFactory) &&
  81.             !iid.equals(Components.interfaces.nsIObserver)) {
  82.             this.log("Adblock content policy factory object: QI unknown interface: " + iid + "\n");
  83.             throw Components.results.NS_ERROR_NO_INTERFACE;
  84.         }
  85.         return this;
  86.     }
  87. };
  88.  
  89. // module initialisation
  90. function NSGetModule(comMgr, fileSpec) {
  91.     return module;
  92. }
  93.